home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: netcom.com!smryan
- From: smryan@netcom.com (@#$%!?!)
- Subject: Re: How to use assert( )
- Message-ID: <smryanDpKxLz.39v@netcom.com>
- Organization: The Programmer formerly known as S M Ryan
- X-Newsreader: TIN [version 1.2 PL1]
- References: <4kc3k7$dur@orion.cybercom.net>
- Date: Tue, 9 Apr 1996 05:22:47 GMT
- Sender: smryan@netcom18.netcom.com
-
- #include <assert.h>
-
- assert(some_expression_which_must_be_true);
-
- as in
-
- assert(f=fopen("name","r"));
-
- If the expression is false, the program is aborted. On a Unix system, it
- will print the file name, line number, and the failed expression to stderr.
- In the example, if fopen returns a non-null result, the expression will
- be true. If the file cannot be openned, the assertion fails.
-
- If you look at assert.h on your system, you'll see it's not too complicated.
- And you can easily write your own to do a long jump, or pop up a dialog, or
- whatever else pleases you.
-
-
- And if you are confident or macho enough that you don't want to use run time
- to check assertions, you can do something like
-
- #define NDEBUG
- #include <assert.h>
-
- The assert(predicate) is elided.
-
-
- Unlike some languages, C assertions have no special syntax or semantics.
-
- --
- The Queen, amused, in quiet power, | smryan@netcom.com PO Box 1563
- will draw the son to darkenned bower. | Cupertino, California
- Her face is fair, her fragrance rare, | (xxx)xxx-xxxx 95015
- with woven webs for wayward flower. | I don't use no smileys
-